import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gex_news/conntroller/MoviesController.dart';
import 'package:flutter_gex_news/conntroller/baseNNavi/CustomAppBar.dart';
import 'package:flutter_gex_news/utils/ImageCache.dart';
import 'package:get/get.dart';

class MovieListView extends StatelessWidget {

  final MovieController controller = Get.put(MovieController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppbar(title: "getx-mvc",isSHowBack: true).build(context);
      body: Obx((){
        if(controller.isLoading.value){
          return CircularProgressIndicator();
        }else{
          return ListView.builder(
              itemCount: controller.movieslist.length,
              itemBuilder: (context,index){
                return _item(context, index);
              });
        }
      }),
    );
  }

  Widget _item(BuildContext context, int index){
    return Container(
      child: Column(
        children: [
          Container(
            width: 100,
            height: 100,
            padding: EdgeInsets.all(8.0),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(6.0),
              child: ImageCacher(imageUrl: controller.movieslist[index].itemCover,width: 100,height: 100,).build(context),
            ),
          ),
          Flexible(child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
               Text(controller.movieslist[index].author,style: TextStyle(fontSize: 16,color: Colors.black87),)
            ],
          )),
          Container(
            color: Colors.grey.shade300,
            height: 2,
          )
        ],
      ),
    );
  }
}
